<template>
  <common-edit-dialog
    :title="dialogTitle"
    :visible.sync="dialogShow"
    :button-loading="buttonLoading"
    @cancel="close"
    @submit="submitForm"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="" prop="opt">
        <el-checkbox-group v-model="form.opt" @change="change">
          <el-checkbox
            v-for="(item, index) in handleMode"
            :label="item.value"
            :key="index"
            >{{ item.label }}
          </el-checkbox>
        </el-checkbox-group>
      </el-form-item>
    </el-form>
  </common-edit-dialog>
</template>

<script>
import { workOrder_workDeal } from "@/api/alarmCenter/index";

import { mapState } from "vuex";

export default {
  components: {},
  props: {},
  data() {
    return {
      dialogTitle: "新增", // 标题
      dialogShow: false, // 是否显示
      form: {
        opt: [0],
        alarmIds: "",
      },
      buttonLoading: false,
      rules: {
        opt: [
          {
            type: "array",
            required: true,
            message: "请选择处理方式",
            trigger: "blur",
          },
        ],
      },
    };
  },
  watch: {},
  computed: {
    ...mapState({
      handleMode: (state) => state.dict.handleMode,
    }),
  },
  methods: {
    change(e) {
      console.log(e);
    },
    /**
     * 关闭
     */
    close() {
      this.$refs.form.resetFields();
      this.dialogShow = false;
      this.$emit("refresh");
    },
    /**
     * 显示
     */
    show(id) {
      this.form.alarmIds = id;
      this.dialogTitle = "人工处理";
      this.dialogShow = true;

      console.log(this.handleMode);
    },
    /**
     * 提交
     */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.buttonLoading = true;
          const data = { ...this.form };
          data.opt = data.opt.join(",");
          workOrder_workDeal(data)
            .then((res) => {
              if (res && res.code === 200) {
                this.$GlobalSuccessMessage("处理成功");
                this.close();
              } else {
                this.$GlobalErrorConfirm("处理失败", res.msg);
              }
            }).finally(()=>{
              this.buttonLoading = false;
            })
        }
      });
    },
  },
  created() {},
  mounted() {},
};
</script>
<style lang="scss" scoped>
</style>
